home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 347_01.zip / TAVLFIND.C < prev    next >
C/C++ Source or Header  |  1993-04-13  |  946b  |  35 lines

  1. /*:file:version:date: "%n    V.%v;  %f"
  2.  * "TAVLFIND.C    V.9;  27-Apr-91,12:04:38"
  3.  *
  4.  *  Purpose: Find id:item in tree
  5.  *
  6.  *  Released to the PUBLIC DOMAIN
  7.  *
  8.  *               author:    Bert C. Hughes
  9.  *                          200 N.Saratoga
  10.  *                          St.Paul, MN 55104
  11.  *                          Compuserve 71211,577
  12.  */
  13.  
  14. #include "tavltree.h"
  15. #include "tavlpriv.h"
  16.  
  17. TAVL_nodeptr tavl_find(TAVL_treeptr tree, void *key)
  18.                 /* Return pointer to tree node containing data-item
  19.                    identified by "key"; returns NULL if not found */
  20. {
  21.     register TAVL_nodeptr p = Leftchild(tree->head);
  22.     register int side;
  23.     while (p)
  24.     {
  25.         side = (*tree->cmp)(key,(*tree->key_of)(p->dataptr));
  26.         if (side > 0)
  27.             p = Rightchild(p);
  28.         else if (side < 0)
  29.             p = Leftchild(p);
  30.         else
  31.             return p;
  32.     }
  33.     return NULL;
  34. }
  35.